package com.qmds.userserver.user.service.impl;


import com.qmds.common.minio.utils.MinioUtils;
import com.qmds.userserver.user.service.UploadService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * --- 天道酬勤 ---
 *
 * @author zhanghanxuan
 * @date 2024/8/26
 * @desc
 */

@Service
public class UploadServiceImpl implements UploadService {
    @Resource
    private MinioUtils minioUtil;

    @Override
    public String upload(MultipartFile file) {
        // 获取原始文件名,aa.jpg
        String fileName = file.getOriginalFilename();

        String uuid = UUID.randomUUID().toString().replace("-", "");
        // 修改文件名，按照指定的规则修改，本例增加了一个时间戳
        String[] split = fileName.split("\\.");
        if (split.length > 1) {
            fileName = uuid + "." + split[1];
        } else {
            fileName = uuid;
        }
        String path = minioUtil.upload(file, fileName);
        return path;
    }
}
